package com.jxbeidou.generate.controller;

import com.jxbeidou.core.constents.ValidateConstants;
import com.jxbeidou.core.entity.PageResult;
import com.jxbeidou.core.entity.R;
import com.jxbeidou.core.validate.ModifyValidateGroup;
import com.jxbeidou.core.validate.SaveValidateGroup;
import com.jxbeidou.generate.dto.DatabaseTypeSaveDTO;
import com.jxbeidou.generate.query.DatabaseTypeQueryDTO;
import com.jxbeidou.generate.query.page.DatabaseTypePageQueryDTO;
import com.jxbeidou.generate.service.DatabaseTypeService;
import com.jxbeidou.generate.vo.DatabaseTypeVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: jxbeidou-basic
 * @ClassName: DatabaseTypeController
 * @description: 数据库类型管理
 * @author: 杜晓祥
 * @create: 2024-03-13 11:36
 * 版权所有：交信北斗(北京)信息科技有些公司
 */
@Slf4j
@RestController
@RequestMapping("/generate/database-type")
@Tag(name = "代码生成项目管理")
public class DatabaseTypeController {
    
    @Resource
    private DatabaseTypeService databaseTypeService;


    @PostMapping("/page")
    @Operation(summary = "分页查询")
    public R<PageResult<DatabaseTypeVO>> page(@RequestBody @Valid DatabaseTypePageQueryDTO query){
        PageResult<DatabaseTypeVO> page = databaseTypeService.page(query);
        return R.success(page);
    }

    @PostMapping("/list")
    @Operation(summary = "查询所有符合数据")
    public R<List<DatabaseTypeVO>> list (@RequestBody @Valid DatabaseTypeQueryDTO query) {
        return R.success(databaseTypeService.list(query));
    }

    @GetMapping("/{id}")
    @Operation(summary = "ID查询")
    public R<DatabaseTypeVO> get(@PathVariable("id") @NotNull(message = ValidateConstants.FIND_ID_NULL) Long id){
        return R.success(databaseTypeService.findById(id));
    }

    @PostMapping
    @Operation(summary = "新增")
    public R<String> save(@RequestBody @Validated(SaveValidateGroup.class) DatabaseTypeSaveDTO vo){
        databaseTypeService.save(vo);
        return R.saveSuccess();
    }

    @PutMapping
    @Operation(summary = "修改")
    public R<String> update(@RequestBody @Validated(ModifyValidateGroup.class) DatabaseTypeSaveDTO vo){
        databaseTypeService.modify(vo);
        return R.modifySuccess();
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "ID删除")
    public R<String> delete(@PathVariable("id") @NotNull(message = ValidateConstants.DELETE_ID_NULL) Long id){
        databaseTypeService.delete(id);
        return R.deleteSuccess();
    }

    @PutMapping("/delete")
    @Operation(summary = "批量删除")
    public R<String> delete(@RequestBody @NotEmpty(message = ValidateConstants.DELETE_IDS_NULL) List<Long> idList) {
        databaseTypeService.deleteForList(idList);
        return R.deleteSuccess();
    }
    
}
